package com.sfy.mallchat.common.common.event.listener;

import com.sfy.mallchat.common.common.event.UserBlackEvent;
import com.sfy.mallchat.common.user.dao.UserDao;
import com.sfy.mallchat.common.user.service.IUserBackpackService;
import com.sfy.mallchat.common.user.service.cache.UserCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
public class UserBlackListener {

    @Autowired
    private IUserBackpackService userBackpackService;


    @Autowired
    private UserDao userDao;

    @Autowired
    private UserCache userCache;

    @Async
    @TransactionalEventListener(classes = UserBlackEvent.class,phase = TransactionPhase.AFTER_COMMIT)
    public void changeUserStatus(UserBlackEvent event) throws Throwable {
        userDao.isvalid(event.getUser().getId());
    }


    @Async
    @TransactionalEventListener(classes = UserBlackEvent.class,phase = TransactionPhase.AFTER_COMMIT)
    public void evictUserStatus(UserBlackEvent event) throws Throwable {
        userCache.EvictRoleMap();
    }
}
